1 package junit.quilt.textui;
2
3
4
5 import junit.textui.*;
6
7 import junit.runner.*;
8
9 import junit.framework.*;
10
11
12
13 import junit.quilt.*;
14
15 import junit.quilt.reports.*;
16
17 import junit.quilt.runner.*;
18
19 import junit.quilt.framework.*;
20
21
22
23 import java.io.*;
24
25
26
27 import org.apache.commons.cli.*;
28
29
30
31 public class Quilt
32
33 extends junit.textui.TestRunner
34
35 {
36
37 private QuiltRegistry registry = null;
38
39 private QuiltSuiteLoader loader = null;
40
41
42
43 public Quilt( QuiltRegistry registry ) {
44
45 this.registry = registry;
46
47 loader = new QuiltSuiteLoader( registry.getInstClassLoader() );
48
49 }
50
51
52
53 public TestSuiteLoader getLoader() {
54
55 return loader;
56
57 }
58
59
60
61 protected TestResult exec( String testCase, boolean wait ) {
62
63 Test suite = getTest( testCase );
64
65 return doRun( suite, wait );
66
67 }
68
69
70
71 public static void main(String args[]) {
72
73 try {
74
75 Options opts = new QuiltOptions();
76
77 CommandLine cl = null;
78
79
80
81 opts.addOption('w', "wait", true,
82
83 "Pause after tests?");
84
85 opts.addOption('c', "class", true,
86
87 "Huh?");
88
89 opts.addOption('F', "reportfile", true,
90
91 "File to write coverage report to.");
92
93 try {
94
95 cl = opts.parse( args );
96
97 } catch (Exception e) {
98
99 usage();
100
101 System.exit( -2 );
102
103 }
104
105
106
107 if (cl.hasOption( QuiltOptions.OPT_HELP )) {
108
109 usage();
110
111 System.exit(0);
112
113 } else if (cl.hasOption( QuiltOptions.OPT_VERSION )) {
114 version();
115 System.exit(0);
116 } else if (!cl.hasOption(QuiltOptions.OPT_REGISTRY)) {
117 err("***You must specify a registry class using the -q option");
118 } else if (!cl.hasOption(QuiltOptions.OPT_TEST)) {
119 err("***You must specify a test class using the -t option");
120 } else if (!cl.hasOption(QuiltOptions.OPT_REPORT)) {
121 err("***You must specify a report class using the -r option");
122 }
123
124 String quiltReg = cl.getOptionValue( QuiltOptions.OPT_REGISTRY );
125
126 String testCase = cl.getOptionValue( QuiltOptions.OPT_TEST );
127
128 String reporter = cl.getOptionValue( QuiltOptions.OPT_REPORT );
129
130 String reportFile = cl.getOptionValue( 'F' );
131
132
133 Class reg = null;
134 try {
135 reg = Class.forName( quiltReg );
136 } catch (Exception cnfe) {
137 System.out.println("Couldn't find registry class: " + quiltReg + "; please ensure it's on the CLASSPATH");
138 cnfe.printStackTrace();
139 System.exit(-2);
140 }
141
142 QuiltRegistry registry = (QuiltRegistry) reg.newInstance();
143
144
145
146 Quilt q = new Quilt( registry );
147
148 TestResult r = q.exec( testCase, cl.hasOption( 'w' ) );
149
150
151 if (!r.wasSuccessful())
152
153 System.exit( -1 );
154
155
156
157 Class rep = Class.forName( reporter );
158
159 Report report = (Report) rep.newInstance();
160
161
162
163 OutputStream out = System.out;
164
165 if (reportFile != null)
166
167 out = new FileOutputStream( reportFile );
168
169
170
171 report.writeReport( out,
172
173 registry );
174
175 System.exit(0);
176
177 } catch (Exception e) {
178
179 e.printStackTrace();
180
181 System.exit(-2);
182
183 }
184
185 }
186
187
188
189 public static String version() {
190
191 return "JUnit Quilt version 0.1 (alpha)";
192
193 }
194
195 public static void usage() {
196
197 System.err.println( version() );
198
199 System.err.println();
200
201 System.err.println("Usage: java junit.quilt.textui.Quilt");
202
203 System.err.println("\t-q | --registry\tRegistry Class which manages instrumentation.");
204
205 System.err.println("\t-t | --test\tTest Class to execute.");
206
207 System.err.println("\t-w | --wait\tWait after each test is executed.");
208
209 System.err.println("\t-F | --reportfile\tFile to write report to.");
210
211 System.err.println("\t-v | --version\tPrint Version information.");
212
213 System.err.println("\t-h | --help\tPrint this message");
214
215 }
216
217 private static void err(String msg) {
218 System.err.println();
219 System.err.println(msg);
220 System.err.println();
221 usage();
222 System.exit(-2);
223 }
224
225 }
226
This page was automatically generated by Maven